#include<bits/stdc++.h>
using namespace std;

int f[200005];

int n, m;

void init() {
    for(int i = 1; i <= n; i++)
        f[i] = i;
}

int find(int x) {
    if(f[x] != x)	f[x] = find(f[x]);
    return f[x];
}

void union_set(int x, int y) {
    x = find(x);
    y = find(y);
    if(x != y)	f[x] = f[y];
}

signed main() {
//	system("start https://www.lanqiao.cn/problems/1135/learning/");

    cin >> n >> m;

    init();

    while(m--) {
        int op, x, y;
        cin >> op >> x >> y;
        if(op == 1) {
            union_set(x, y);
        } else {
            if(find(x) == find(y))
                cout << "YES\n";
            else
                cout << "NO\n";
        }
    }

    return 0;
}

